package model.quality;
import model.database.LogDAO;

import org.springframework.util.Assert;

public class LogAssert {

	private LogDAO LDAO;

	
	private Assert assertiva;

	
	public LogDAO getLDAO() {
		return LDAO;
	}

	public void setLDAO(LogDAO ldao) {
		LDAO = ldao;
	}

	public void addLog(String classe, String method, String text, int kind){
		Log log = new Log();
		log.setClasse(classe);
		log.setKind(1);
		log.setText(text);
		log.setMethod(method);
		LDAO.insertLog(log);
	}
	
	public boolean notNull(Object arg0,String classe, String method, String text) throws IllegalArgumentException{
		try {
			assertiva.notNull(arg0);
			return true;
		}
		catch (IllegalArgumentException ex){
			addLog(classe,method,text,1);	
			throw ex;
		}	
	}
	
	public boolean hasText(String arg0,String arg1,String classe, String method, String text) throws IllegalArgumentException{
		try {
			assertiva.hasText(arg0, arg1);
			return true;
		}
		catch (IllegalArgumentException ex){
			addLog(classe,method,text,10);	
			throw ex;
		}			
	}
	
	public boolean isTrue(Boolean arg0,String arg1,String classe, String method, String text) throws IllegalArgumentException{
		try {
			assertiva.isTrue(arg0, arg1);
			return true;
		}
		catch (IllegalArgumentException ex){
			addLog(classe,method,text,2);	
			throw ex;
		}			
	}


	public boolean isEqualNumber(long arg0,long arg1,String classe, String method, String text) throws IllegalArgumentException{
		if (arg0-arg1==0) {
			return true;
		}
		else {
			addLog(classe,method,text,3);	
			IllegalArgumentException ex=new IllegalArgumentException();
			throw ex;
		}			
	}
}
